package com.zd.kids.DataBean;

import com.blankj.utilcode.util.StringUtils;
import com.blankj.utilcode.util.TimeUtils;
import com.zd.kids.R;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * @ClassName: com.zd.kids.DataBean
 * @Description:
 * @Author: hyy
 * @Date: 2020/6/26
 * @Time: 9:29 PM
 */
public class UserInfo {

    /**
     * name : Bear
     * gender : 男
     * mobile : 61236004
     * email : a@b.com
     * photo : defalut
     * birthday : 1592802640
     * countryid : 3
     * result : [{"groupid_id":1,"classroomid":"232672722"},{"groupid_id":2,"classroomid":"8932257"},{"groupid_id":3,"classroomid":"36547641"}]
     */

    private String name;
    private String gender;
    private String mobile;
    private String email;
    private String photo;
    private long birthday;
    private int countryid;
    private int countrycode;

    public int getCountrycode() {
        return countrycode;
    }

    public void setCountrycode(int countrycode) {
        this.countrycode = countrycode;
    }

    private List<ResultBean> result;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPhoto() {
        return photo;
    }

    public String getAge() {
        int age = 0;
        try {
            Date birthDay = new Date(getBirthday() * 1000);
            //获取当前系统时间
            Calendar cal = Calendar.getInstance();
            //如果出生日期大于当前时间，则抛出异常
            if (cal.before(birthDay)) {
                throw new IllegalArgumentException(
                        "The birthDay is before Now.It's nbelievable!");
            }
            //取出系统当前时间的年、月、日部分
            int yearNow = cal.get(Calendar.YEAR);
            int monthNow = cal.get(Calendar.MONTH);
            int dayOfMonthNow = cal.get(Calendar.DAY_OF_MONTH);
            //将日期设置为出生日期
            cal.setTime(birthDay);
            //取出出生日期的年、月、日部分
            int yearBirth = cal.get(Calendar.YEAR);
            int monthBirth = cal.get(Calendar.MONTH);
            int dayOfMonthBirth = cal.get(Calendar.DAY_OF_MONTH);
            //当前年份与出生年份相减，初步计算年龄
            age = yearNow - yearBirth;
            //当前月份与出生日期的月份相比，如果月份小于出生月份，则年龄上减1，表示不满多少周岁
            if (monthNow <= monthBirth) {
                //如果月份相等，在比较日期，如果当前日，小于出生日，也减1，表示不满多少周岁
                if (monthNow == monthBirth) {
                    if (dayOfMonthNow < dayOfMonthBirth) age--;
                } else {
                    age--;
                }
            }
            System.out.println("age:" + age);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return age + StringUtils.getString(R.string.s_age);
    }

    public void setPhoto(String photo) {
        this.photo = photo;
    }

    public long getBirthday() {
        return birthday;
    }

    public void setBirthday(long birthday) {
        this.birthday = birthday;
    }

    public int getCountryid() {
        return countryid;
    }

    public void setCountryid(int countryid) {
        this.countryid = countryid;
    }

    public List<ResultBean> getResult() {
        return result;
    }

    public void setResult(List<ResultBean> result) {
        this.result = result;
    }

    public static class ResultBean {
        /**
         * groupid_id : 1
         * classroomid : 232672722
         */

        private int groupid_id;
        private String title;

        private boolean status;

        public boolean isStatus() {
            return status;
        }

        public void setStatus(boolean status) {
            this.status = status;
        }

        public String getTitle() {
            return title;
        }

        public void setTitle(String title) {
            this.title = title;
        }

        private String classroomid;

        public int getGroupid_id() {
            return groupid_id;
        }

        public void setGroupid_id(int groupid_id) {
            this.groupid_id = groupid_id;
        }

        public String getClassroomid() {
            return classroomid;
        }

        public void setClassroomid(String classroomid) {
            this.classroomid = classroomid;
        }
    }
}
